#include <string>
#include <cstdlib>
#include <fstream>
using namespace std;

int MainWindow::read()
{
	string line;
	static float new_perc = 0.0;
	ifstream data(".D.tmp");
	if(!data.is_open())	return 3;

	char down_size[30], speed[10];
	int perc = 0;
	size_t found;

		while( getline(data,line) )
		{
	
			if(line == "ERROR")	return 2;

			if(line == "COMPLETE")	
			{
				m_ProgressBar.set_fraction(1);
				Down.set_label("COMPLETE");
				return 1;
			}
			else
			{
				found = line.find('\t');
				int i=0, j=0;
	
				{
					char temp[3];

					for( i=0; line[i] != '\t'; ++i)
						temp[i] = line[i];

					perc = atoi(temp);
					new_perc = (float) perc / 100;
				}

				for (i = found+1, j=0; line[i] != '\t'; ++i, ++j)
					down_size[j] = line[i];
				down_size[j] = '\0';

				for (i = i+1, j=0; line[i] != '\0'; ++i, ++j)
					speed[j] = line[i];
				speed[j] = '\0';
			}
		}
		m_ProgressBar.set_fraction(new_perc);
		Down.set_label(down_size);
		Speed.set_label(speed);

		data.clear();

}
